package edu.sctu;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "loginServlet")
public class loginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//     seeino空间定义变量能让所有页面访问
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        HttpSession session=request.getSession();
        PrintWriter out=response.getWriter();

            if ("admin".equals(username) && "123456".equals(password)) {

//                out.println("登陆成功");
                session.setAttribute("islogin", "true");

                response.sendRedirect("userList");

            } else {
                session.setAttribute("islogin", "fals");
                response.sendRedirect("wrong.jsp");

            }
            out.close();

    }
}
